{% extends 'base.html' %}
{% load book_tags %}

{% block content %}
<ul class="list-articles">
    {% for book in books %}
    <li>
        <div class="article-panel">
            <p class="first">Жанр: {{ book.genre.genre }}</p>
            <br>
            <p class="first">Автор статьи: {{ book.creator.username|default:"Без автора" }}</p>
        </div>
        {% if book.photo %}
        <p>
            <img src="{{ book.photo.url }}" alt="oops" class="img-article-left thumb">
        </p>
        {% else %}
        <p>
            <img src="{{ default_cover }}" alt="oops" class="img-article-left">
        </p>
        {% endif %}
        <h2>{{ book.title }}, {{ book.author.name }} {{ book.author.surname }}</h2>
        <span><i>Рейтинг: </i></span>
        {% show_rating book.rating %}
        <br>
        {% with tags=book.tags.all %}
        {% if tags %}
        <p style="display: inline;"><i>Теги: </i></p>
        {% for t in tags %}
        {% if not forloop.last %}
        <p style="display: inline;">
            <a href="{{ t.get_absolute_url }}">{{ t.tag }}, </a>
        </p>
        {% else %}
        <p style="display: inline;">
            <a href="{{ t.get_absolute_url }}">{{ t.tag }}</a>
        </p>
        {% endif %}
        {% endfor %}
        {% endif %}
        {% endwith %}
        {% autoescape off %}
        {{book.description|linebreaks|truncatewords:40}}
        {% endautoescape %}
        <div class="clear"></div>
        <p class="link-read-post"><a href="{{ book.get_absolute_url }}">Подробнее о книге</a></p>
    </li>
    {% endfor %}
</ul>
{% endblock %}

{% block pagination %}
{% if page_obj.has_other_pages %}
<nav class="list-pages">
    <ul>
        {% if page_obj.has_previous %}
        <li class="page-start-end">
            <a href="?page=1"> В начало </a>
        </li>
        {% endif %}
        {% for page_number in paginator.page_range %}
        {% if page_obj.number == page_number %}
        <li class="page-num page-num-selected">{{ page_number }}</li>
        {% elif page_number >= page_obj.number|add:-2 and page_number <= page_obj.number|add:2 %}
        <li class="page-num">
            <a href="?page={{ page_number }}">{{ page_number }}</a>
        </li>
        {% endif %}
        {% endfor %}

        {% if page_obj.has_next %}
        <li class="page-start-end">
            <a href="?page={{ paginator.num_pages }}"> В конец </a>
        </li>
        {% endif %}
    </ul>
</nav>
{% endif %}
{% endblock %}